<!--
 * @Description  : 删除
 * @Author       : zhao
 * @Date         : 2022-07-28 09:53:21
 * @LastEditors  : zhao
 * @LastEditTime : 2023-01-31 15:55:14
-->


<template>
    <div class='delete'>

        <el-popover trigger="click" placement="bottom" width="180" ref="delButton">
            <p style="padding-bottom: 10px" v-if="user.zTable.mdName.name == 'useUpdataMaintain'">请确认删除档案：<span
                    style="color:#79bbff">{{ title }}</span> </p>
            <p style="padding-bottom: 10px" v-else>确认要删除此数据吗？</p>

            <div style="text-align: center; margin: 0">
                <el-button size="mini" @click="cancelRemove">取消</el-button>
                <el-button type="danger" size="mini" @click="deletes">确定</el-button>
            </div>
            <template #reference>
                <!-- @click.native.prevent.stop="delTips()" -->
                <el-button type="danger" size="mini" @click="tipsTitle" :loading="user.buttonLoading">删除
                </el-button>
            </template>

        </el-popover>

    </div>
</template>

<script setup lang='ts'>
import { ref, getCurrentInstance, nextTick } from 'vue'
import { useTableInfo } from '/@/stores/ztable'
import { ElMessage } from 'element-plus'
const user = useTableInfo()
let title = ref("确认要删除此数据吗？")
const deletes = () => {
    cancelRemove()
    if (!user.zTable.selectRows || user.zTable.selectRows.length == 0) {
        ElMessage.error("请选择数据");

    } else {

        user.zTableFunDelShow = true

    }

}


const delButton: any = ref();
let visible: any = ref(false)
const delTips = () => {

    if (!user.zTable.selectRows || user.zTable.selectRows.length == 0) {
        ElMessage.error("请选择数据");

        cancelRemove()

    } else {
        cancelShow()
    }

}

const cancelRemove = () => {

    delButton.value.hide()
}
const cancelShow = () => {

    delButton.value.afterEnter()
}

const tipsTitle = () => {


    if (user.zTable.mdName.name == "useUpdataMaintain") {
        let id = ""
        if (user.zTable.selectRows.length > 0) {

            user.zTable.selectRows.forEach((e, index) => {
                if (user.zTable.selectRows.length - 1 == index) {
                    id = id + e.id

                } else {
                    id = id + e.id + '、'

                }
            });
        }

        console.log("🚀 ~ file: delete.vue:78 ~ tipsTitle ~ id", id)
        title.value = `
        ${id}
        `

    } else {
        title.value = "确认要删除此数据吗？"
    }

}
</script>
<style lang='scss' scoped>
</style>